{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=199
  Verdict: Accepted
}
uses SysUtils, Math;
 
var
	n,k:longint;
 
function gcd(a,b:int64):int64;
 
	procedure swap(var a,b:int64);
 
	var
		t:int64;
 
	begin
	t:=a;
	a:=b;
	b:=t;
	end;
 
begin
if a<b then swap(a,b);
while b>0 do begin
	a:=a mod b;
	swap(a,b);
end;
result:=a;	
end;
 
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n,k);
write(gcd(n,k));
end.